/*
 * Created on 11-ene-2010
 *
 */
package com.grupobbva.iici.util;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;

import com.grupobbva.iici.serializable.Corporativa;

/**
 * @author Administrador
 *
 */
public class CorporativaOracleDaoFactory {
	
		
	public Corporativa obtenerPorPK(String codMult, String codEle) throws Exception {

		Corporativa bean = null;
		String sql = "select * from tiici_corporativa where cod_mult='"+codMult+"' and valor1 ='"+codEle+"'";
		System.out.println("SENTENCIA SQL : " + sql);
		Context initialContext;
		Connection con = null;
	
		try {
			
			initialContext = new InitialContext();
			DataSource datasource = (DataSource) initialContext.lookup("jdbc/IICI");
			con = datasource.getConnection();
			Statement s = con.createStatement();
			ResultSet rs = s.executeQuery(sql);
			
			
			while (rs.next()) {
				bean = new Corporativa();
				bean.setCodMult(rs.getString(1));
				bean.setCodEle(rs.getString(2));
				bean.setValor1(rs.getString(3));
				bean.setValor2(rs.getString(4));
				bean.setValor3(rs.getString(5));
				bean.setValor4(rs.getString(6));
			}
			rs.close();
			s.close();

		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			con.close();
		}
		
		return bean;
	

	}
	
	
}
